package lcmpt;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.util.Collection;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

public final class MarkedTreeNodeRenderer extends DefaultTreeCellRenderer {

	private final Collection<DefaultMutableTreeNode> markedNodes;
	 

	public MarkedTreeNodeRenderer(Collection<DefaultMutableTreeNode> markedNodes) {
		super();
		this.markedNodes = markedNodes;
	}

	@Override
	public Component getTreeCellRendererComponent(final JTree tree,
			final Object value, final boolean isSelected,
			final boolean isExpanded, final boolean isLeaf, final int row,
			final boolean hasFocus) {
		super.getTreeCellRendererComponent(tree, value, isSelected, isExpanded,
				isLeaf, row, hasFocus);

		if (value instanceof DefaultMutableTreeNode) {
			final DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
			setMetaAttributes(tree, node);
		}
		return this;
	}

	private void setMetaAttributes(final JTree tree,
			final DefaultMutableTreeNode node) {
		if (markedNodes.contains(node)) {
			setFont(getFont().deriveFont(Font.BOLD, 14));
			setText("> " + getText() + " <");
			setForeground(Color.blue);
		} else {
			setFont(tree.getFont());
		}
	}
}